package com.example.smartcity_poverty.ui.poverty.adapter

import android.content.Intent
import com.example.smartcity_poverty.Base.BaseRecyclerAdapter
import com.example.smartcity_poverty.ui.poverty.activity.ShowMoreOneActivity
import com.example.smartcity_poverty.ui.poverty.activity.ShowNewsActivity
import com.example.smartcity_poverty.ui.poverty.model.PtNewsEntity
import kotlinx.android.synthetic.main.re_item_poverty_news.*
import kotlinx.android.synthetic.main.re_item_poverty_news.view.*

/**
 *  created by ikun
 *  ANDROID STUDIO - version 4.0
 *  email: jinkunwei41@gmail.com
 * --------------------------------
 *
 **/
class PtNewsAdapter(
    val list: MutableList<PtNewsEntity>,
    private val layoutId: Int
) : BaseRecyclerAdapter<PtNewsEntity>(list, layoutId) {
    override fun setData(
        view: BaseViewHolder.ViewFind,
        data: PtNewsEntity,
        position: Int,
        holder: BaseViewHolder
    ) {
        if (list.size <= 0){

        }else{
            val d = list[position]
            holder.viewFind.ptNewsImage.setImageResource(d.ptNewsImage)
            holder.viewFind.ptNewsTitle.text = d.ptNewsTitle
            holder.viewFind.ptNewsContent.text = d.ptNewsContent
            holder.viewFind.ptNewsTime.text = d.ptNewsTime

            val con = holder.viewFind.view?.context
            holder.itemView.setOnClickListener {
                if (holder.viewFind.ptNewsTitle.text.toString() == "走进精准扶贫“首倡地”——湖南湘西十八洞村")
                    con?.startActivity(Intent(con, ShowMoreOneActivity::class.java))
                else {
                    con?.startActivity(Intent(con, ShowNewsActivity::class.java).apply {
                        putExtra("title", holder.viewFind.ptNewsTitle.text.toString())
                        putExtra("image", d.ptNewsImage)
                        putExtra("content", holder.viewFind.ptNewsContent.text.toString())
                    })
                }


            }
        }


    }

}